//
//  MYWelcomeViewController.swift
//  swift2.0项目开始
//
//  Created by 龚昕炜 on 16/7/31.
//  Copyright © 2016年 龚昕炜. All rights reserved.
//

import UIKit

class MYWelcomeViewController: UIViewController {

    override func loadView() {
        view = bgImageView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
//        view.backgroundColor = UIColor.whiteColor()
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        setUpUI()
        
        startAnimation()
    }
    
    func startAnimation() {
    
        UIView.animateWithDuration(2.0, delay: 0.0, usingSpringWithDamping: 0.7, initialSpringVelocity: 10, options: [], animations: { [weak self] () -> Void in
            self!.photoImageView.center = CGPointMake(self!.view.bounds.size.width * 0.5, 200)
            }) { (_) -> Void in
                NSNotificationCenter.defaultCenter().postNotificationName(kNotificationChangeViewController, object: self)
        }
    }
    
    func setUpUI() {
        view.addSubview(photoImageView)
        view.addSubview(textLabel)
    
        photoImageView.bounds = CGRectMake(0, 0, 170 * 0.5, 170 * 0.5)
        photoImageView.center = CGPointMake(view.bounds.size.width * 0.5, 400)
        
        textLabel.sizeToFit()
        textLabel.center = CGPointMake(view.bounds.size.width * 0.5, 280)
    }
    
    
    /** 背景 */
    private lazy var bgImageView: UIImageView = {
        
        let image = UIImageView()
        
        image.image = UIImage(named: "ad_background")
        
        return image
    }()
    
    /** 头像 */
    private lazy var photoImageView: UIImageView = {
    
        let image = UIImageView()
        
        image.image = UIImage(named: "avatar_default_big")
        
        image.layer.cornerRadius = 170 * 0.5 * 0.5
        
        image.layer.masksToBounds = true

//        image.clipsToBounds = true
        
        image.layer.borderColor = UIColor.yellowColor().CGColor
        
        image.layer.borderWidth = 2.0
        
        return image
    }()
    
    /** 欢迎文字 */
    private lazy var textLabel: UILabel = {
        
        let lbl = UILabel()
        
        lbl.text = "欢迎回来"
        
        lbl.textAlignment = .Center
        
        lbl.textColor = UIColor.darkGrayColor()
        
        lbl.font = UIFont.systemFontOfSize(16)
        
        return lbl
    }()

}
